import request from '@/utils/request'
import axios from 'axios'
const CryptoJS = require('crypto-js')

const appid = 'B79uUqP4wjKxqp339etuEx50dGEGz23a'
const timestamp = new Date().getTime()
// console.log(timestamp)
const appsecurity = 'm3veBt1cpMubPTqO9NBC2YY9J9PM3FA4'
const str = `${appid}&${timestamp}&${appsecurity}`
const sign = CryptoJS.MD5(str).toString()
// console.log(sign)
// 获取企业信息
export const getEnterpriseData = (keyword) =>
  axios('https://api.shumaidata.com/v4/business2/get', {
    params: {
      appid,
      timestamp,
      sign,
      keyword
    }
  })

// 查询客户档案分页信息
export const getCompanyRegisterApi = (params) =>
  request.get('/pio-microservice-biz/pio/manage-register/page', { params })

// 保存管理单位组织机构（步骤一）
export const saveCompanyRegister1Api = (params) => {
  let url = `/pio-microservice-biz/pio/manage-register/organization/save?companyName=${params.companyName}&identityCode=${params.identityCode}&manageUserMobile=${params.manageUserMobile}&manageUserName=${params.manageUserName}`
  if (params.parentOrgNo) {
    url += `&parentOrgNo=${params.parentOrgNo}`
  }
  return request.post(url)
}

// 获取业务范围
export const getBusinessApi = (params) =>
  request.get('/core/security/biz-role/list?status=1', params)

// 保存管理单位业务范围（步骤二）
export const saveCompanyRegister2Api = (params) =>
  request.post(
    `/pio-microservice-biz/pio/manage-register/authority/save?businessScope=${params.businessScope}&id=${params.id}`
  )

// 保存管理单位设备信息（步骤三）
export const saveCompanyRegister3Api = (data) =>
  request.post('/pio-microservice-biz/pio/manage-register/device/save', data)

// 保存管理单位业务范围（步骤二）
export const saveCompanyRegister4Api = (params) =>
  request.post(
    `/pio-microservice-biz/pio/manage-register/coordinate/save?latitude=${params.latitude}&longitude=${params.longitude}&id=${params.id}`
  )

// 重新编辑管理单位注册业务范围
export const saveCompanyRegisterSqApi = (params) =>
  request.post(
    `/pio-microservice-biz/pio/manage-register/authority/edit?businessScope=${params.businessScope}&id=${params.id}`
  )

// 获取当前登录人信息
export const getUserNoApi = () =>
  request.get('/pio-microservice-biz/pio/common/user/org')

// 是否有新增合作伙伴
export const isAddApi = () =>
  request.get('/pio-microservice-biz/pio/common/user/is-platform-user')

// 状态字典
export const getStatusValueApi = () =>
  request.get('/core/dictionary/combo-item/list?dictType=ZCGL_ZT')

// id获取明细
export const getInfoDataApi = (params) =>
  request.get('/pio-microservice-biz/pio/manage-register/detail', { params })

// 删除
export const delCompanyRegisterApi = (id) =>
  request.post(`/pio-microservice-biz/pio/manage-register/delete?id=${id}`)
